package chaoyue.study.jdbc;

import chaoyue.study.jdbc.utils.DbUtils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ResourceBundle;

/**
 * 资源的关闭和释放
 */
public class Test2_Statement3 {
    public static void main(String[] args) {
        // 使用try-resource处理资源的关闭
        try (Connection connection = DbUtils.getConnection();
             Statement statement = connection.createStatement();
             ResultSet resultSet = statement.executeQuery("select id,username,password,birthday from test_user")
        ) {
            // 使用while循环来打印所有的结果集
            while (resultSet.next()) {
                System.out.println("id=" + resultSet.getInt("id"));
                System.out.println("username=" + resultSet.getString("username"));
                System.out.println("password=" + resultSet.getString("password"));
                System.out.println("birthday=" + resultSet.getString("birthday"));
            }
        } catch (Exception ignored) {

        }
    }
}
